package cn.llming.gift.util;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.util.UUID;

@Configuration
public class SendEmailUtil {
    @Value("${send.timeout}")
    private static int timeout;




    public static void testSend(String user,String title,Long shopId,String toUser,JavaMailSender javaMailSender){

        //创建复杂邮件对象
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        //发送复杂邮件的工具类

        try {
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true,"utf-8");

            helper.setFrom(user);
            helper.setSubject(title);
            RedisUtils instance = RedisUtils.INSTANCE;
            String uuId= UUID.randomUUID().toString();
            instance.set("uuId",uuId,60);
              // http://img30.360buyimg.com/popWaterMark/jfs/t1/67988/7/14094/232759/5db64acfE6ab2b09e/38b5cb3dc38b4b1f.jpg"
              helper.setText("恭喜你，审核通过，请在30分钟类进行激活 ;<a href='http://127.0.0.1:8080/shop/activet/"+shopId+"?uuId="+uuId+"'>连接</a>",true);

            //添加附件
//            helper.addAttachment("罗宾.jpg",new File("C:\\Users\\hm\\Desktop\\work\\aa.jpg"));
//            helper.addAttachment("压缩文件", new File("C:\\Users\\hm\\Desktop\\20191010\\2020-02-05-智能商贸-DAY4\\resources\\resources.zip"));
            //收件人
            helper.setTo(toUser);

            javaMailSender.send(mimeMessage);
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }



    public static void send(String toUser,JavaMailSender javaMailSender,String note){
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        //设置发送人
        mailMessage.setFrom("2304143496@qq.com");
        //邮件主题
        mailMessage.setSubject("店铺未成功激活");
        //邮件内容
        mailMessage.setText("审核失败"+note);
        //收件人
        mailMessage.setTo(toUser);

        javaMailSender.send(mailMessage);
    }

    public static void sendEmalByPhone(String toUser,JavaMailSender javaMailSender,String note,String title){
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        //设置发送人
        mailMessage.setFrom("2304143496@qq.com");
        //邮件主题
        mailMessage.setSubject(title);
        //邮件内容
        mailMessage.setText(note);
        //收件人
        mailMessage.setTo(toUser);

        javaMailSender.send(mailMessage);
    }




}
